package com.juli.v2xdemo.util;

import android.content.Context;
import android.util.Log;
import android.view.View;

import com.juli.v2xdemo.PlaneWar;
import com.juli.v2xdemo.entity.Car;
import com.juli.v2xdemo.listener.AddHeroListener;

/**
 * Created by juli on 2019/9/28.
 */

public class MyCar_Utils {
    public   static Car mCarData;
    //初始位置
    static   float road_basex =1330 ;
    static   float road_1_x =850 +50;
    static   float road_2_x =1100 +50 ;
    static   float road_3_x =1330 +50;
    static   float road_4_x =1580+50 ;
    static  float road_basey = 900;
    static  float road_y = 900-50;
    public  static  void add_mycar(PlaneWar planeWar, Context context) {

          mCarData = new Car(context);
        mCarData.setX(road_basex);
        mCarData.setY(road_basey);
        mCarData.setVisibility(View.INVISIBLE);
        mCarData.getViewTreeObserver().addOnGlobalLayoutListener(
                new AddHeroListener(mCarData));
        planeWar.setmCarData(mCarData);
        planeWar.addView(mCarData);
//        planeWar.moveHeroTo(road_basex, road_basey); //变道-偏移角度注释掉该行
    }

    /**
     * 移动车到某条道路
     * @param road
     */
    public  static void movemycar(int road,PlaneWar planeWar){
        switch (road) {
            case 1:

                planeWar.moveHeroTo(road_1_x, road_y);
                break;
            case 2:
                planeWar.moveHeroTo(road_2_x, road_y);
                getcarposition();
                break;
            case 3:
                planeWar.moveHeroTo(road_3_x, road_y);
                break;
            case 4:
                planeWar.moveHeroTo(road_4_x, road_y);
                break;


            default:
                break;
        }

    }

    public  static void getcarposition(){
//        float x  ;
//        int[] location = new int[2];
//        mCarData.getLocationOnScreen(location);
//        x = location[0];
//        float y = location[1];
//        Log.d("test", "Screenx--->" + x + "  " + "Screeny--->" + y);
//        mCarData.getLocationInWindow(location);
//        x = location[0];
//        y = location[1];
//        Log.d("test", "Window--->" + x + "  " + "Window--->" + y);
//        Log.d("test", "left:" + mCarData.getLeft());
//        Log.d("test", "right:" + mCarData.getRight());
//        Log.d("test", "Top:" + mCarData.getTop());
//        Log.d("test", "Bottom:" + mCarData.getBottom());
//        Log.d("test", "Width:"+mCarData.getWidth());
//        Log.d("test", "Height:"+mCarData.getHeight());
//        Screenx--->1091.0  Screeny--->721.0
//        Window--->1091.0  Window--->721.0
//        left:0
//        right:118
//        Top:0
//        Bottom:258
//        Width:118
//        Height:258
        Log.d("test", "TranslationX:"+ mCarData.getTranslationX());
        Log.d("test", "TranslationY:"+ mCarData.getTranslationY());
        Log.d("test", "X:"+ mCarData.getX());
        Log.d("test", "Y:"+ mCarData.getY());
//          //1091.0
//          // 721.0
//         X:1330.0
//         Y:900.0
    }



}
